﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDD4Fun.Observer;

namespace DDD4Fun.Ducks
{
    public class DuckyObservable : IObservable
    {
        List<IObserver> observers = new List<IObserver>();
        IObservable duck;

        public DuckyObservable(IObservable duck)
        {
            this.duck = duck;
        }

        #region IObservable Members

        public void Register(Observer.IObserver anObserver)
        {
            observers.Add(anObserver);
        }

        public void UnRegister(Observer.IObserver anObserver)
        {
            observers.Remove(anObserver);
        }

        /// <summary>
        /// 直接操作类中的duck对象 不处理anObject
        /// </summary>
        /// <param name="anObject"></param>
        public void NotifyObservers(object anObject)
        {
            foreach (var observer in observers)
            {
                observer.Notify(anObject);
            }
        }

        #endregion
    }
}
